
using System;
using System.Text;
using SpotifyGenNHibernate.CEN;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Exceptions;
using SpotifyGenNHibernate.EN.Spotify;

namespace SpotifyGenNHibernate.CAD.Spotify
{
        public partial class ColaDeReproduccionCAD : BasicCAD, IColaDeReproduccionCAD
        {
        public ColaDeReproduccionCAD() : base ()
        {
        }

        public ColaDeReproduccionCAD(ISession sessionAux) : base (sessionAux)
        {
        }



        public ColaDeReproduccionEN ReadOIDDefault (int id)
        {
                ColaDeReproduccionEN colaDeReproduccionEN = null;

                try
                {
                        SesssionInitializeTransaction ();
                        colaDeReproduccionEN = (ColaDeReproduccionEN)session.Load (typeof(ColaDeReproduccionEN),
                                id

                                );
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ColaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return colaDeReproduccionEN;
        }


        public int New_ (ColaDeReproduccionEN colaDeReproduccion)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        if (colaDeReproduccion.Usuario != null) {
                                colaDeReproduccion.Usuario = (SpotifyGenNHibernate.EN.Spotify.UsuarioEN)session.Load (typeof(SpotifyGenNHibernate.EN.Spotify.UsuarioEN), colaDeReproduccion.Usuario.Id);
                        }

                        session.Save (colaDeReproduccion);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ColaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return colaDeReproduccion.Id;
        }

        public void Destroy (int id)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        ColaDeReproduccionEN colaDeReproduccionEN = (ColaDeReproduccionEN)session.Load (typeof(ColaDeReproduccionEN),
                                id

                                );
                        session.Delete (colaDeReproduccionEN);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ColaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }
        }

        public System.Collections.Generic.IList<ColaDeReproduccionEN> Consultar (int first, int size)
        {
                System.Collections.Generic.IList<ColaDeReproduccionEN> result = null;
                try
                {
                        SesssionInitializeTransaction ();
                        if (size > 0)
                                result = session.CreateCriteria (typeof(ColaDeReproduccionEN)).
                                         SetFirstResult (first).SetMaxResults (size).List<ColaDeReproduccionEN>();
                        else
                                result = session.CreateCriteria (typeof(ColaDeReproduccionEN)).List<ColaDeReproduccionEN>();
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ColaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return result;
        }
        }
}
